package com.littcore.saap.assistant.dao;

import java.util.List;

import com.littcore.dao.GenericHibernateDao;
import com.littcore.saap.assistant.po.UserFavourite;
import com.littcore.saap.assistant.po.UserPortlet;
import com.littcore.saap.core.web.util.LoginUtils;


/**
 * .
 * 
 * <pre><b>描述：</b>
 *    
 * </pre>
 * 
 * <pre><b>修改记录：</b>
 *    
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">蔡源</a>
 * @since 2015年6月24日
 * @version 1.0
 */
public class UserPortletDao extends GenericHibernateDao<UserPortlet, Integer> {
	
  public int countByUid(int userId, String portletUid)
  {      
    String hql = "select count(o) from UserPortlet o where o.userId=? and o.portletUid=?";
    return super.count(hql, new Object[]{userId, portletUid});
  }
  
	/**
	 * List by user.
	 *
	 * @param userId the user id
	 * @return the list
	 */
	public List<UserPortlet> listByUser(int userId) {
		String hql = "from UserPortlet where userId=? order by positionX asc, positionY asc";
		return super.listAll(hql,new Object[]{userId});
	}
	
	public int getMaxPositionX(int userId) {
	  String hql = "select max(positionX) from UserPortlet where userId=?";
	  Integer max = super.uniqueResult(hql,new Object[]{userId}, Integer.class);
	  return max==null?0:max;
	}
	
	public int getMaxPositionY(int userId) {
    String hql = "select max(positionY) from UserPortlet where userId=?";
    Integer max = super.uniqueResult(hql,new Object[]{userId}, Integer.class);
    return max==null?0:max;
  }

}
